package com.xzx;

import jakarta.jms.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/9/10 15:09
 */
public class PersistentTest {
    private Connection connection = null;
    private Session session = null;
    private Queue queue = null;
    private Topic topic = null;
    @Before
    public void init() throws Exception {
        connection = AmqUtil.getConnection();
        session = connection.createSession();
        queue = session.createQueue("xzx");
        topic = session.createTopic("xzx");
    }

    @After
    public void close() throws Exception {
        session.close();
        AmqUtil.closeConnection(connection);
    }

    @Test
    public void test() throws Exception {

        MessageProducer producer = session.createProducer(topic);

        TextMessage message = session.createTextMessage();
        message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        message.setText("hello world333");
        message.setJMSExpiration(System.currentTimeMillis() + 1000 * 10);
        producer.send(message);
        producer.close();
    }
}
